package nz.ac.massey.groupproject.ecs2;

import java.awt.event.KeyEvent;


class KeyBindings {
	// ======================================== surface area ========================================
	// Any interaction with other modules must go through the following APIs.
	// (purpose: minimize intertwinings & make them explicit)

	static boolean kdown(int k)  { return GUI.isKeyDown(k); }
	static boolean kdown(char c) { return GUI.isKeyDown((int) c); }

	static void issueCommand(UserCommand cmd) { Main.issueCommand(cmd); }



	// ======================================== internal ========================================
	public static class TranslateKeypressesToCommands implements ECSSystem {
		public void globalTick() {
			if (kdown(KeyEvent.VK_ESCAPE)) issueCommand(UserCommand.QUIT);
			if (kdown('Q')) issueCommand(UserCommand.QUIT);

			if (kdown('A')) issueCommand(UserCommand.LEFT);
			if (kdown('D')) issueCommand(UserCommand.RIGHT);
			if (kdown('W')) issueCommand(UserCommand.FORWARD);
			if (kdown('S')) issueCommand(UserCommand.BACK);
		}
	}
}
